package utils

import (
	"github.com/lzk97224/gomail"
	log "github.com/sirupsen/logrus"
)

func SendMail(subject string, toMail []string, fileNames ...string) error {

	m := gomail.NewMessage()
	m.SetHeader("From", "lizhikui@xiaoniangao.com")

	m.SetHeader("To", toMail...)

	m.SetHeader("Subject", subject)
	m.SetBody("text/html", "<b>"+subject+"</b>")
	for _, filename := range fileNames {
		m.Attach(filename)
	}
	d := gomail.NewDialer("smtp.exmail.qq.com", 465, "lizhikui@xiaoniangao.com", "qcaaqmcZwmJdYA64")
	if err := d.DialAndSend(m); err != nil {
		log.Errorf("发送邮件失败，err:%v", err)
		return err
	}
	log.Infof("发送邮件成功，TO:%v", toMail)
	return nil
}
